package com.qi.demo01.Demo;

import java.util.concurrent.CountDownLatch;

/**
 * @author zjq
 * @date 2020/3/27 14:24
 */

//计数器
//相当于一个房子内有6个人，必须等到6个人都走完才可以锁门
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "出去");
                countDownLatch.countDown();//线程数量减一
            }, String.valueOf(i)).start();
        }
        countDownLatch.await();//等待计数器归零，然后向下执行
        System.out.println("close door");
    }
}
